package com.streambolics.worseminton.servlet;

import javax.servlet.http.HttpServletRequest;

import com.streambolics.std.HtmlBuilder;
import com.streambolics.worseminton.data.Event;

public class EventCommentHandler extends EventHandler
{
    private static final long serialVersionUID = 1L;

    @Override
    protected void formatBodyAsSimpleDesktopHtml (HtmlBuilder aBuilder, Event aResponseObject) throws Exception
    {
        Snippets.generateEventComment (aBuilder, aResponseObject, "/go/EventComment", "Comment");
    }

    @Override
    protected Event generateResponseObject (HttpServletRequest aRequest) throws Exception
    {
        Event e = getReferencedEvent ();
        if (requireWritePermission (e))
        {
            if (getParameter ("COMMENT") == null)
            {
                warnAbout (new Exception ("Please enter a comment"));
            }
            else
            {
                updateEvent (e);
                e.sendEmails ();
            }
        }
        return e;
    }

    @Override
    protected String getRedirect (Event aResponseObject)
    {
        return aResponseObject.getIdUrl ("/go/Event");
    }

}
